package com.rajaev.dtu.tractor.interfaces;

import cn.hutool.core.util.StrUtil;
import com.rajaev.dtu.tractor.app.service.StatisticService;
import com.rajaev.dtu.tractor.domain.vo.StatisticQueryVo;
import com.rajaev.dtu.tractor.domain.vo.StatisticResultVo;
import com.rajaev.dtu.tractor.infrastructure.base.errors.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutionException;

import static com.rajaev.dtu.tractor.infrastructure.base.errors.ErrorCodes.ERR_QUERY_TYPE;


/**
 * 统计数据
 *
 * @Created with IDEA
 * @author: tianjie
 * @Date:2019/6/14
 * @Time:11:32
 */
@RestController
public class BatterStaticController {

    @Autowired
    StatisticService statisticService;


    @GetMapping("/statistic/view")
    public StatisticResultVo queryStatistic(StatisticQueryVo statisticQueryVo) throws ExecutionException, InterruptedException {
        switch (statisticQueryVo.getType()){
            case BY_VIN:
                return statisticService.queryAvgChargeInfo(statisticQueryVo.getStartDate(),statisticQueryVo.getEndDate(),statisticQueryVo.getCondition());
            case BY_CUSTOMER:
                return statisticService.queryAvgChargeInfoByCustomerId(statisticQueryVo.getStartDate(),statisticQueryVo.getEndDate(),statisticQueryVo.getCondition().split(StrUtil.COMMA));
            case BY_PROJECT_TEAM:
                return statisticService.queryAvgChargeInfoByProjectTeam(statisticQueryVo.getStartDate(),statisticQueryVo.getEndDate(),statisticQueryVo.getCondition().split(StrUtil.COMMA));
        }
        throw new BusinessException(ERR_QUERY_TYPE);
    }
}
